package com.lanou.moving.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.lanou.moving.R;
import com.lanou.moving.adapter.SingerContentSongAdapter;
import com.lanou.moving.entity.SearchSingerSong;
import com.lanou.moving.utils.MyConfig;
import com.lanou.moving.volley.GsonRequest;
import com.lanou.moving.volley.VolleySingleton;

import java.util.List;

/**
 * Created by dllo on 15/10/28.
 */
public class SingerSongsFragment extends Fragment {
    private String url;
    private ListView song_listview;
    private VolleySingleton volleySingleton;
    private List<SearchSingerSong.DataEntity> datas;
    private SingerContentSongAdapter adapter;
    private int _id;
    private GsonRequest<SearchSingerSong> singerSongGsonRequest;
    private Context context;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = getActivity();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.search_song_listview,null);
        song_listview= (ListView) view.findViewById(R.id.song_listview);
        volleySingleton=VolleySingleton.getInstance(context);
        initData();
        return view;
    }

    private void initData() {
       _id = MyConfig.getSharePreInt(getActivity(), "entity", "_id");
        url = "http://api.dongting.com/song/singer/"+ _id +"/songs?uid=867831024341380&f=62&os=4.4.4&app=ttpod&hid=1280524740415150&imei=867831024341380&alf=702008&from=android&resolution=1080x1920&net=2&api_version=1.0&agent=none&size=30&v=v8.2.0.2015091720&utdid=VeKf29%2BKwt4DANT3MxDH4mCl&s=s200&address=%E8%BE%BD%E5%AE%81%E7%9C%81%E5%A4%A7%E8%BF%9E%E5%B8%82%E6%B2%99%E6%B2%B3%E5%8F%A3%E5%8C%BA%E4%BA%94%E4%B8%80%E8%B7%AF314%E5%8F%B7&page=1&longitude=121.54457&user_id=0&latitude=38.88346&language=zh&imsi=460029049930817&tid=0";

        Log.i("lkl", "" + url);

        singerSongGsonRequest = new GsonRequest<>(url, SearchSingerSong.class, new Response.Listener<SearchSingerSong>() {
            @Override
            public void onResponse(SearchSingerSong response) {
                datas = response.getData();
                Log.i("LANOU", "====  " + datas.get(0).getName());
                adapter = new SingerContentSongAdapter(context, datas);
                song_listview.setAdapter(adapter);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
        volleySingleton.addQueue(singerSongGsonRequest);

    }


}
